package com.ashin.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class HelloController {

    @RequestMapping("/hello")
    public String hello(Model model) {
        System.out.println("hello");
        model.addAttribute("firstKey", "hello world");


        return "views/hello";
    }

    @RequestMapping("/testException")
    public ModelAndView testException(Model model) {
        System.out.println("testException");
        model.addAttribute("firstKey", "hello world");

        ModelAndView mv = new ModelAndView("hello");
        int i = 0;
        int j = 1 / i;

        return mv;
    }

    @RequestMapping("/json")
    @ResponseBody
    public Object testJson() {
        List<Object> list = new ArrayList<>();
        list.add("zjh");
        list.add("zjh1");
        list.add("zjh2");
        list.add(new Date());
        list.add(null);
        list.add("zjh23");

        return list;
    }

    @RequestMapping("/testJson")
    @ResponseBody
    public Object testJsonException() {
        System.out.println("testJson");
        List<Object> list = new ArrayList<>();
        list.add("zjh");
        list.add("zjh1");
        list.add("zjh2");
        list.add(new Date());
        list.add(null);
        list.add("zjh23");

        int i = 0;
        int j = 1 / i;

        return list;
    }

}
